package io.gitee.caoxiaoyu97.log4j.defender;

import com.cxy.common.config.ConfigUtils;
import com.cxy.common.util.SpringUtils;
import io.gitee.caoxiaoyu97.log4j.defender.condition.StringKeyDefenderEnableCondition;
import io.gitee.caoxiaoyu97.log4j.defender.constants.DefenderConstants;
import io.gitee.caoxiaoyu97.log4j.defender.matcher.KeyMatcher;
import io.gitee.caoxiaoyu97.log4j.defender.matcher.StringKeyMatcher;
import io.gitee.caoxiaoyu97.log4j.defender.message.trace.StringMessageDefender;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

import static io.gitee.caoxiaoyu97.log4j.defender.constants.DefenderConstants.LOG_DEFENDER_T3EVENT_MAX_VALUE_LEN;

@Conditional({StringKeyDefenderEnableCondition.class})
public class TraceLogDefenderConfiguration {
    @Bean
    public StringKeyMatcher stringKeyDefenderMatcher() {
        return new StringKeyMatcher(ConfigUtils.get(DefenderConstants.LOG_DEFENDER_T3EVENT_STRING_KEYS, ""));
    }

    @Bean
    public StringMessageDefender stringMessageDefender() {
        return new StringMessageDefender(SpringUtils.getBeansValues(KeyMatcher.class),
                ConfigUtils.get(DefenderConstants.LOG_DEFENDER_T3EVENT_MAX_VALUE_LEN, "1000"),
                ConfigUtils.get(DefenderConstants.LOG_DEFENDER_MARKER_VALUE, "******"));
    }
}
